<?php
require_once 'vendor/autoload.php';

// 初始化应用
$app = new \think\App();
$app->initialize();

use app\model\SystemConfig;

try {
    echo "测试晓风API...\n";
    
    $token = SystemConfig::getConfig('xiaofeng_create_order_token');
    echo "Token: " . substr($token, 0, 20) . "...\n";
    
    // 测试获取店铺列表
    $url = 'https://api-fuwu.zzbtool.com/xf/dy/oneorder/memberMallAuthRelation/listV2';
    $params = [
        'appId' => 9,
        'page' => 1,
        'size' => 100
    ];

    // 使用正确的认证方式
    $headers = [
        'token: ' . $token,
        'Content-Type: application/json',
        'Accept: application/json'
    ];

    echo "\n使用token认证方式: token: " . substr($token, 0, 20) . "...\n";

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url . '?' . http_build_query($params));
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_TIMEOUT, 30);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

        $response = curl_exec($ch);
        $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        $error = curl_error($ch);
        curl_close($ch);

        echo "HTTP状态码: $httpCode\n";
        echo "响应: $response\n";
        
        if ($error) {
            echo "cURL错误: $error\n";
        }
        
        // 检查响应
        $data = json_decode($response, true);
        if ($data && isset($data['success']) && $data['success']) {
            echo "API调用成功！\n";
        } else {
            echo "API调用失败: " . ($data['msg'] ?? '未知错误') . "\n";
        }
    
} catch (Exception $e) {
    echo "错误: " . $e->getMessage() . "\n";
} 